package com.yedou.entity;

import com.yedou.init.AbstractCache;
import com.yedou.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CategoryCache extends AbstractCache {

    private static final String SYS_CATEGORY_CACHE_KEY = "CATEGORY";

    @Autowired
    private RedisUtil redisUtil;

    @Override
    public void initCache() {
        redisUtil.set("dish", "鱼");
    }

    @Override
    public <T> T getCache(String key) {
        if(!redisUtil.hashKey(key)){
            reloadCache();
        }
        return (T) redisUtil.get(key);
    }

    @Override
    public void clearCache() {
        redisUtil.del(SYS_CATEGORY_CACHE_KEY);
    }
}
